<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>tv</h1>
    <a href="/ctl.html">遥控器页面</a>
    <button id="btn">测试发送</button>
    <script src="./peerjs.min.js"></script>
    <script>
      const ID = "tv" + new Date().getTime();
      console.log("ID", ID);
      let conn;
      // 获取按钮
      const btn = document.getElementById("btn");
      btn.addEventListener("click", () => {
        // doing
      });
      function connect(ID, callback) {
        // 创建Peer对象
        const peer = new Peer(ID, {
          host: "localhost",
          port: 9998,
          path: "/web_tv",
        });
        // 监听连接事件
        peer.on("open", (id) => {
          console.log("连接成功，ID为：" + id);
        });
        peer.on("connection", function (conn) {
          console.log("connection suc");
          conn.on("open", function () {
            console.log("connection open");
            // Receive messages
            conn.on("data", function (data) {
              console.log("Received", data);
            });
            // Send messages
            conn.send("Hello!");
          });
        });
      }
      connect();
    </script>
  </body>
</html>
